
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.sound.sampled.LineUnavailableException;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;


public class RivincitaFrame extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JButton btnRivincita;
	private JButton btnClose;
    private RivincitaFrame t;
    private Option gameOption;
    private GameObjectPanel game;
    private int nBall;
	/**
	 * Create the dialog.
	 */
	public RivincitaFrame(final String winner ,final Option gameOption) {
		this.gameOption = gameOption;
		game = gameOption.getGameObjectPanel();
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				gameOption.getGameFrame().dispose();
				gameOption.getMenu().setVisible(true);
			}
		});
		
		setResizable(false);
		nBall = gameOption.getnBalls() ;
		t=this;
		setBounds(100, 100, 488, 237);
		getContentPane().setLayout(new BorderLayout());
		BackgroundImgPanel sfondo = new BackgroundImgPanel("./images/vittoria.png");
		sfondo.setLayout(new BorderLayout());
		getContentPane().add(sfondo);
	
		  setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
//		contentPanel.add(sfondo);
		getContentPane().add(sfondo, BorderLayout.CENTER);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(SystemColor.textText);
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				btnRivincita = new JButton("Rivincita");
				btnRivincita.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						gameOption.getGameFrame().dispose();
						MainFrameGame pannelloGioco = new MainFrameGame(gameOption,gameOption.getMenu());
						t.dispose();
					}
				});
				btnRivincita.setForeground(Color.CYAN);
				btnRivincita.setActionCommand("OK");
				getRootPane().setDefaultButton(btnRivincita);
			}
			{
				btnClose = new JButton("Chiudi");
				btnClose.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent arg0) {
						t.dispose();
						
						gameOption.getGameObjectPanel().getParentFrame().dispose();
						System.exit(0);
						
					}
				});
				btnClose.setForeground(Color.CYAN);
				btnClose.setActionCommand("Cancel");
			}
			
			JLabel messageWinner = new JLabel(winner + " VINCE ");
			messageWinner.setForeground(Color.CYAN);
			messageWinner.setFont(new Font("Lucida Grande", Font.PLAIN, 19));
			GroupLayout gl_buttonPane = new GroupLayout(buttonPane);
			gl_buttonPane.setHorizontalGroup(
				gl_buttonPane.createParallelGroup(Alignment.LEADING)
					.addGroup(gl_buttonPane.createSequentialGroup()
						.addGap(14)
						.addComponent(messageWinner)
						.addGap(54)
						.addComponent(btnRivincita)
						.addGap(32)
						.addComponent(btnClose)
						.addGap(121))
			);
			gl_buttonPane.setVerticalGroup(
				gl_buttonPane.createParallelGroup(Alignment.LEADING)
					.addGroup(gl_buttonPane.createSequentialGroup()
						.addGap(5)
						.addGroup(gl_buttonPane.createParallelGroup(Alignment.LEADING)
							.addComponent(messageWinner)
							.addGroup(gl_buttonPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(btnRivincita)
								.addComponent(btnClose))))
			);
			buttonPane.setLayout(gl_buttonPane);
		}
		
		
	}
}
